package com.uni.action;

import com.uni.entity.User;
import com.uni.service.Service;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebListener;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * --------------project-------------
 *
 * @Author Unirithe  - Mr.Chao
 * - CSDN:
 * https://blog.csdn.net/Unirithe
 * - GitHub:
 * https://github.com/unirithe
 * @create 2021/12/24 14:17
 * ------------------------------------------
 */
@WebServlet(name = "OrderInsertAction", urlPatterns = "/addOrder")
public class OrderInsertAction extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        User user = (User) req.getSession().getAttribute("userInfo");
        Integer uid = user.getId();
        Integer cid = Integer.parseInt(req.getParameter("cid"));
        if(uid!=null && cid!=null){
            boolean ok = Service.order.insertOrder(uid, cid);
            resp.getWriter().write(ok == true ? "操作成功" : "操作失败");
        } else{
            resp.getWriter().write("缺少商品ID或者用户ID参数");
        }
    }
}
